<template>
<div>

  <h1>学生页面</h1>
  姓名 <input type="text" v-model="form.name">
  年龄 <input type="text" v-model="form.age">
  <button @click="add">添加</button>


  <p>展示此老师下的所有学生</p>
  <ul>
    <li v-for="i in stulist">{{i.name}}</li>
  </ul>

</div>
</template>

<script>
export default {
  name: "Stu",
  data(){
    return{
      stulist:[],
      form:{'teacher':localStorage.getItem("tuserid")},
      tid:localStorage.getItem("tuserid")
    }
  },
  methods:{
    add(){
      this.axios.post('stu/',this.form).then(res=> {
        console.log(res)
      })
      this.getStu()
    },
    getStu(){
      this.axios.get("stu/?id="+this.tid).then(res=>{
        if(res.data.code==200){
          this.stulist=res.data.list
        }
      })
    }
  },
  mounted() {
    if(!this.tid){
      alert('请登录后操作')
      this.$router.push({"path":'/tlogin'})
    }
    this.getStu()
  },
}
</script>

<style scoped>

</style>
